package com.ruoyi.eqmonitor.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.eqmonitor.dtos.*;
import com.ruoyi.eqmonitor.service.OpenApiService;
import com.ruoyi.eqmonitor.utils.OpenApiUtil;
import com.ruoyi.eqmonitor.vo.OpenApiVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

@Slf4j
@Api(tags = "环保数据开放接口")
@RestController
@RequestMapping("/openApi")
public class OpenApiController {

    @Resource
    private OpenApiService openApiService;

    @ApiOperation("获取授权污染源在线监控企业站点信息")
    @GetMapping("/getMnData")
    public String getMnData() {
        Map<String, String> map = new HashMap<>();
        return OpenApiUtil.doPost(map, "getMnData");
    }

    @ApiOperation("获取污染源在线监控最新实时数据")
    @GetMapping("/getThkRealData")
    public String getThkRealData(OpenApiDto openApiDto) {
        Map<String, String> map = new HashMap<>();
        map.put("mn", openApiDto.getMn());
        if (openApiDto.getStartTime() != null) {
            map.put("start_time", openApiDto.getStartTime());
            map.put("end_time", openApiDto.getEndTime());
        }
        return OpenApiUtil.doPost(map, "getThkRealData");
    }

    @ApiOperation("获取站点日均数据")
    @GetMapping("/getDayOpenData")
    public String getDayOpenData(DayOpenDataDto dayOpenDataDto) {
        Map<String, String> map = new HashMap<>();
        map.put("type", "1");
        map.put("mn", dayOpenDataDto.getMn());
        map.put("company_id", dayOpenDataDto.getCompanyId());
        if (dayOpenDataDto.getStartTime() != null) {
            map.put("start_time", dayOpenDataDto.getStartTime());
            map.put("end_time", dayOpenDataDto.getEndTime());
        }
        return OpenApiUtil.doPost(map, "getDayOpenData");
    }

    @ApiOperation("污水厂进出水数据报表")
    @GetMapping("/reportForms")
    public List<OpenApiVo> reportForms(OpenApiReportFormsDto dto) {
        return openApiService.reportForms(dto);
    }

    @ApiOperation("污水厂进出水数据报表-导出")
    @Log(title = "污水厂进出水数据报表-导出", businessType = BusinessType.EXPORT)
    @PostMapping("/reportForms/export")
    public void reportFormsExport(HttpServletResponse response, OpenApiReportFormsDto dto){
        List<OpenApiVo> list = openApiService.reportForms(dto);
        ExcelUtil<OpenApiVo> util = new ExcelUtil<OpenApiVo>(OpenApiVo.class);
        util.exportExcel(response, list, "污水厂进出水数据报表");
    }

}
